﻿/*
 * Rational, originally TIFFRational
 * 
 * Copyright (c) 2001, 2002 Marco Schmidt.
 * All rights reserved.
 * 
 * C# translation and update 
 * Copyright (c) Adam Sida, asida@centrum.cz
 * 
 * All rights reserved.
 */
using System;
using System.Collections.Generic;
using System.Text;


namespace Petra.Gis.ImagingServices.Tiff
{

///<summary>
/// Data class to store a TIFF rational number.
/// A TIFF rational number is a fraction given by 32 bit integer numerator and denominator values.
/// It is one of the data types used in TIFF tags ({@link TIFFTag}).
/// For more information on TIFF's internals, see {@link TIFFCodec}, which lists a few links 
/// to TIFF specification documents.
///</summary>
public class Rational
{
	private int _numerator;
	private int _denominator;


  /// <summary>
  /// Creates a TiffRational object from the arguments.
  /// </summary>
  /// <param name="numerator">the numerator of the fraction stored in this object</param>
  /// <param name="denominator">denominator of the fraction stored in this object</param>
	public Rational(int numerator, int denominator)
	{
		if (denominator == 0)
		{
			throw new ArgumentException("A zero denominator is not allowed.");
		}
		_numerator = numerator;
		_denominator = denominator;
	}



  ///<summary>
  /// Returns the denominator value that was given to the constructor.
  /// return denominator value
  ///</summary>
	public int Denominator
	{
    get { return _denominator; }
	}




  ///<summary>
  /// Returns the fraction as a <code>double</code> value.
  /// @return the fraction stored in this object
  /// @see getAsFloat
  ///</summary>
	public double getAsDouble()
	{
		return (double)_numerator / (double)_denominator;
	}




	/**
	 * Returns the fraction as a <code>float</code> value.
	 * @return the fraction stored in this object
	 * @see #getAsDouble
	 */
	public float getAsFloat()
	{
		return (float)_numerator / (float)_denominator;
	}




	/**
	 * Returns the numerator value that was given to the constructor.
	 * @return numerator value
	 */
	public int Numerator
	{
    get { return _numerator; }
	}
}

}
